package com.msl.debezium.service.impl;

import com.msl.debezium.common.BizException;
import com.msl.debezium.dto.UserDto;
import com.msl.debezium.mapper.UserMapper;
import com.msl.debezium.request.QueryUserListReq;
import com.msl.debezium.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    private final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<UserDto> queryUserList(QueryUserListReq req) throws Exception {
        List<UserDto> userList;
        try {
            userList = userMapper.queryUserList(req);
        }catch (Exception e){
            logger.error("查询用户时发生异常:{}", e);
            throw new BizException("查询用户信息出错");
        }
        return userList;
    }

    @Override
    public Integer addUser(List<UserDto> list) {
        return userMapper.addUser(list);
    }

    @Override
    public Integer countAddByTable(String table, Date startDate, Date endDate) {
        return userMapper.countAddByTable(table, startDate, endDate);
    }
}
